from collections import OrderedDict

from rest_framework.response import Response


def jwt_response_payload_handler(token, user, request):
    return {
        'username': user.username,
        'token': token,
        'id': user.id,
    }


from rest_framework.pagination import PageNumberPagination
class PageNum(PageNumberPagination):
    # 指定煤业数量参数
    page_size_query_param = 'pagesize'
    # 指定最大返回数量
    max_page_size = 8

    def get_paginated_response(self, data):
        return Response(OrderedDict(
            [
                ('count',self.page.paginator.count),
                ('lists',data),
                ('page',self.page.paginator.num_pages),
                ('pagesize',self.max_page_size)
            ]
        ))

